package com.lcy.web.base

import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.stereotype.Component

/**
 * @author loucy
 * @version 1.0
 */
@Aspect
@Component
open class EmptyStringFilterAop{
    @Around("@annotation(com.lcy.web.base.EmptyStringFilter)")
    fun filter(joinPoint: ProceedingJoinPoint):Any{
        val objects = joinPoint.args
        if(objects != null && objects.isNotEmpty()){
            for(i in 0 .. objects.size - 1){
                val obj = objects[i]
                if(obj != null && obj is String && obj.isBlank()){
                    objects[i] = null
                }
            }
        }
        return joinPoint.proceed(objects)
    }
}